package com.dreamthen.controller;

import com.dreamthen.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author zengms
 * @Date 2023-11-07 19:37:04
 **/
@Controller
@RequestMapping("/json")
public class JsonController {

    @RequestMapping("/01")
    public String json01() {
        return "main";
    }

    @RequestMapping("/02")
    @ResponseBody //作为文本返回，不在是视图
    public String json02() {
        System.out.println("*****json02***");
        return "main";
    }

    @RequestMapping("/03")
    @ResponseBody //作为文本返回（user对象文本），不在是视图
    public User json03() {
        System.out.println("*****json03***");
        User user = new User("1","zengms",new Date(),"pwd1");
        return user;
    }

    @RequestMapping("/04")
    @ResponseBody //作为文本返回（user对象文本），不在是视图
    public List<User> json04() {
        List<User> userList = new ArrayList<>();
        System.out.println("*****json04***");
        User user1 = new User("1","zengms",new Date(),"pwd1");
        User user2 = new User("2","张三",new Date(),"pwd2");
        userList.add(user1);
        userList.add(user2);
        return userList;
    }


    @PostMapping("/05")
    @ResponseBody //作为文本返回（user对象文本），不在是视图
    public User json05(@RequestBody User user) {
        System.out.println("*****05***user="+user.toString());
        return user;
    }

    @PostMapping("/06")
    @ResponseBody //作为文本返回（user对象文本），不在是视图
    public List<User> json06(@RequestBody List<User> users) {
        System.out.println("*****json06***users="+users.toString());
        return users;
    }

    @PostMapping("/07")
    @ResponseBody //作为文本返回（user对象文本），不在是视图
    public User json07(User user) {
        System.out.println("*****05***user="+user.toString());
        return user;
    }

}
